<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use App\Models\Banner;
use App\Models\Adv;
use App\Models\Frilink;
use App\Models\Rbanner;
use App\Models\Mbanner;
class SiteController extends BaseController{
	
	public function getBannerindex(){
		return view('site.bannerindex');
	}
	
	//返回DataTable
    public function getBannerdatatable(){
        $dt=array();
        $orderby = isset( $_GET[ 'order'  ] ) ? $_GET[ 'columns' ][ $_GET[ 'order' ][ 0 ][ 'column' ] ][ 'name' ] : 'id';
        $orderdir = isset( $_GET[ 'order'  ] ) ? $_GET[ 'order' ][ 0 ][ 'dir' ] : 'asc';
        $start = Input::get('start',0);//从多少开始
        $length = Input::get('length',10);//数据长度
        $search = $_GET['search']['value'];//搜索获取前台传过来的过滤条件
        $recordsTotal = Banner::count();
        $where='1=1 ';
        if($search!=''){
            $where.='and title like "%'.$search.'%"';
        }
        $data = Banner::whereRaw($where)->select('id', 'title','image','url','status_at')->skip($start)->take($length)->orderBy($orderby,$orderdir)->get();
        $recordsFiltered=  Banner::whereRaw($where)->count();
        $datatable=array();
        $iseditstr='';
        $isdelstr='';
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@getBanneredit')) {
            $iseditstr='<button class="btn-white btn btn-xs" onclick="location.href=\'/site/banneredit/$reeditstr\'">编辑</button>';
        }
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@postBannerdel')) {
            $isdelstr='<button class="btn-white btn btn-xs" onclick="singledel(\'/site/rbannerdel\',$redelstr);">删除</button>';
        }
        foreach ($data as $item) {
            $status_at=$item->status_at==1?'<span class="label label-primary">启用</span>':'<span class="label label-danger">禁用</span>';
            $obj=array('<input type="checkbox" name="chk" value='.$item->id.' />',$item->id,$item->title,'<img width="80px" height="60px" src='.$item->image.' />',$item->url,$status_at,str_replace('$reeditstr',$item->id,$iseditstr).str_replace('$redelstr',$item->id,$isdelstr));
            array_push($datatable,$obj);
        }
        $dt['draw']=intval(Input::get('draw',0));
        $dt['data']=$datatable;
        $dt['recordsTotal']=$recordsTotal;
        $dt['recordsFiltered']=$recordsFiltered;
        // $dt['error']='暂时没有数据';
        echo json_encode($dt);     
    }


    public function getBanneradd(){
        return view('site.banneradd');
    }

    public function postBanneradd(){
        $info = new Banner;
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'添加成功！','redirecturl'=>'/site/bannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'添加失败！','redirecturl'=>'/site/bannerindex']);
        }
    }
    
    public function getBanneredit($id){
        $info = Banner::find($id);
        return view('site.banneredit')->with('info',$info);
    }

    public function postBanneredit(){
        $info = Banner::find(Input::get('id'));
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/bannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/bannerindex']);
        }
    }

    public function postBannerdel(){
        $res=Banner::destroy(Input::get('data'));
        if($res){
            die('1');
        }
        else{
            die('0');
        }
    }

    public function postUploadbanner(){
        if (Input::hasFile('file'))
        {
            $file=Input::file('file');
            if($file -> isValid()){
                $folder='uploads/file/'.date('Ymd');
                if(!file_exists($folder)){
                 mkdir($folder);
                }
                $clientName = $file -> getClientOriginalName();
                // $tmpName = $file->getFileName(); // 缓存在tmp文件夹中的文件名 例如 php8933.tmp 这种类型的.
                // $realPath = $file->getRealPath();    //这个表示的是缓存在tmp文件夹下的文件的绝对路径
                $extension = $file -> getClientOriginalExtension(); //上传文件的后缀.
                // $mimeTye = $file -> getMimeType();//开启php的extension=php_fileinfo.dll
                // $newName = time().$clientName;
                $newName = time().rand(1000, 9999).'.'.$extension;
                $file -> move($folder,$newName);
                // \Image::make($file)->resize(300, 200)->save($folder.'/'.$newName);
                $path='/'.$folder.'/'.$newName;
                // $file->move('uploads');
                $data['file']=array();
                $subdata['name']=$clientName;
                // $subdata['size']=$mimeTye;
                $subdata['url']=$path;
                $data['file'][]=$subdata;
                die(json_encode($data));
            }
        }
    }

    public function getFrilinkindex(){
        return view('site.frilinkindex');
    }
    
    //返回DataTable
    public function getFrilinkdatatable(){
        $dt=array();
        $orderby = isset( $_GET[ 'order'  ] ) ? $_GET[ 'columns' ][ $_GET[ 'order' ][ 0 ][ 'column' ] ][ 'name' ] : 'id';
        $orderdir = isset( $_GET[ 'order'  ] ) ? $_GET[ 'order' ][ 0 ][ 'dir' ] : 'asc';
        $start = Input::get('start',0);//从多少开始
        $length = Input::get('length',10);//数据长度
        $gettypeid=Input::get('search_typeid',0);
        // $search = $_GET['search']['value'];//搜索获取前台传过来的过滤条件
        $recordsTotal = Frilink::count();
        $where='1=1 ';
        // if($search!=''){
        //     $where.='and title like "%'.$search.'%"';
        // }
        $where.=$gettypeid>0?' and xz_frilink.type_id = '.$gettypeid:'';
        $data = Frilink::whereRaw($where)->select('id', 'title','type_id','url','status_at','created_at','updated_at')->skip($start)->take($length)->orderBy($orderby,$orderdir)->get();
        $recordsFiltered=  Frilink::whereRaw($where)->count();
        $datatable=array();
        $iseditstr='';
        $isdelstr='';
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@getFrilinkedit')) {
            $iseditstr='<button class="btn-white btn btn-xs" onclick="location.href=\'/site/frilinkedit/$reeditstr\'">编辑</button>';
        }
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@postFrilinkdel')) {
            $isdelstr='<button class="btn-white btn btn-xs" onclick="singledel(\'/site/frilinkdel\',$redelstr);">删除</button>';
        }
        foreach ($data as $item) {
            $status_at=$item->status_at==1?'<span class="label label-primary">启用</span>':'<span class="label label-danger">禁用</span>';
            $typename='';
            if($item->type_id==1){
                $typename='首页';
            }else if($item->type_id==2){
                $typename='素材';
            }else if($item->type_id==3){
                $typename='专题';
            }
            $obj=array('<input type="checkbox" name="chk" value='.$item->id.' />',$item->id,$item->title,$typename,$item->url,$item->created_at->format('Y-m-d H:i:s'),$item->updated_at->format('Y-m-d H:i:s'),$status_at,str_replace('$reeditstr',$item->id,$iseditstr).str_replace('$redelstr',$item->id,$isdelstr));
            array_push($datatable,$obj);
        }
        $dt['draw']=intval(Input::get('draw',0));
        $dt['data']=$datatable;
        $dt['recordsTotal']=$recordsTotal;
        $dt['recordsFiltered']=$recordsFiltered;
        // $dt['error']='暂时没有数据';
        echo json_encode($dt);     
    }


    public function getFrilinkadd(){
        return view('site.frilinkadd');
    }

    public function postFrilinkadd(){
        $info = new Frilink;
        $info->title = Input::get('title');
        $info->type_id = Input::get('type_id');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'添加成功！','redirecturl'=>'/site/frilinkindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'添加失败！','redirecturl'=>'/site/frilinkindex']);
        }
    }
    
    public function getFrilinkedit($id){
        $info = Frilink::find($id);
        return view('site.frilinkedit')->with('info',$info);
    }

    public function postFrilinkedit(){
        $info = Frilink::find(Input::get('id'));
        $info->title = Input::get('title');
        $info->type_id = Input::get('type_id');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/frilinkindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/frilinkindex']);
        }
    }

    public function postFrilinkdel(){
        $res=Frilink::destroy(Input::get('data'));
        if($res){
            die('1');
        }
        else{
            die('0');
        }
    }

    public function getAdvindex(){
        return view('site.advindex');
    }
    
    //返回DataTable
    public function getAdvdatatable(){
        $dt=array();
        $orderby = isset( $_GET[ 'order'  ] ) ? $_GET[ 'columns' ][ $_GET[ 'order' ][ 0 ][ 'column' ] ][ 'name' ] : 'id';
        $orderdir = isset( $_GET[ 'order'  ] ) ? $_GET[ 'order' ][ 0 ][ 'dir' ] : 'asc';
        $start = Input::get('start',0);//从多少开始
        $length = Input::get('length',10);//数据长度
        $search = $_GET['search']['value'];//搜索获取前台传过来的过滤条件
        $recordsTotal = Adv::count();
        $where='1=1 ';
        if($search!=''){
            $where.='and title like "%'.$search.'%"';
        }
        $data = Adv::whereRaw($where)->select('id', 'title','image','url','status_at')->skip($start)->take($length)->orderBy($orderby,$orderdir)->get();
        $recordsFiltered=  Adv::whereRaw($where)->count();
        $datatable=array();
        $iseditstr='';
        $isdelstr='';
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@getAdvedit')) {
            $iseditstr='<button class="btn-white btn btn-xs" onclick="location.href=\'/site/advedit/$reeditstr\'">编辑</button>';
        }
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@postAdvdel')) {
            $isdelstr='<button class="btn-white btn btn-xs" onclick="singledel(\'/site/advdel\',$redelstr);">删除</button>';
        }
        foreach ($data as $item) {
            $status_at=$item->status_at==1?'<span class="label label-primary">启用</span>':'<span class="label label-danger">禁用</span>';
            $obj=array('<input type="checkbox" name="chk" value='.$item->id.' />',$item->id,$item->title,'<img width="80px" height="60px" src='.$item->image.' />',$item->url,$status_at,str_replace('$reeditstr',$item->id,$iseditstr).str_replace('$redelstr',$item->id,$isdelstr));
            array_push($datatable,$obj);
        }
        $dt['draw']=intval(Input::get('draw',0));
        $dt['data']=$datatable;
        $dt['recordsTotal']=$recordsTotal;
        $dt['recordsFiltered']=$recordsFiltered;
        // $dt['error']='暂时没有数据';
        echo json_encode($dt);     
    }


    public function getAdvadd(){
        return view('site.advadd');
    }

    public function postAdvadd(){
        $info = new Adv;
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'添加成功！','redirecturl'=>'/site/advindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'添加失败！','redirecturl'=>'/site/advindex']);
        }
    }
    
    public function getAdvedit($id){
        $info = Adv::find($id);
        return view('site.advedit')->with('info',$info);
    }

    public function postAdvedit(){
        $info = Adv::find(Input::get('id'));
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/advindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/advindex']);
        }
    }

    public function postAdvdel(){
        $res=Adv::destroy(Input::get('data'));
        if($res){
            die('1');
        }
        else{
            die('0');
        }
    }

    public function postUploadadv(){
        if (Input::hasFile('file'))
        {
            $file=Input::file('file');
            if($file -> isValid()){
                $folder='uploads/file/'.date('Ymd');
                if(!file_exists($folder)){
                 mkdir($folder);
                }
                $clientName = $file -> getClientOriginalName();
                // $tmpName = $file->getFileName(); // 缓存在tmp文件夹中的文件名 例如 php8933.tmp 这种类型的.
                // $realPath = $file->getRealPath();    //这个表示的是缓存在tmp文件夹下的文件的绝对路径
                $extension = $file -> getClientOriginalExtension(); //上传文件的后缀.
                // $mimeTye = $file -> getMimeType();//开启php的extension=php_fileinfo.dll
                // $newName = time().$clientName;
                $newName = time().rand(1000, 9999).'.'.$extension;
                $file -> move($folder,$newName);
                // \Image::make($file)->resize(300, 200)->save($folder.'/'.$newName);
                $path='/'.$folder.'/'.$newName;
                // $file->move('uploads');
                $data['file']=array();
                $subdata['name']=$clientName;
                // $subdata['size']=$mimeTye;
                $subdata['url']=$path;
                $data['file'][]=$subdata;
                die(json_encode($data));
            }
        }
    }

    public function getRbannerindex(){
        return view('site.rbannerindex');
    }
    
    //返回DataTable
    public function getRbannerdatatable(){
        $dt=array();
        $orderby = isset( $_GET[ 'order'  ] ) ? $_GET[ 'columns' ][ $_GET[ 'order' ][ 0 ][ 'column' ] ][ 'name' ] : 'id';
        $orderdir = isset( $_GET[ 'order'  ] ) ? $_GET[ 'order' ][ 0 ][ 'dir' ] : 'asc';
        $start = Input::get('start',0);//从多少开始
        $length = Input::get('length',10);//数据长度
        $search = $_GET['search']['value'];//搜索获取前台传过来的过滤条件
        $recordsTotal = Rbanner::count();
        $where='1=1 ';
        if($search!=''){
            $where.='and title like "%'.$search.'%"';
        }
        $data = Rbanner::whereRaw($where)->select('id', 'title','image','url','status_at')->skip($start)->take($length)->orderBy($orderby,$orderdir)->get();
        $recordsFiltered=  Rbanner::whereRaw($where)->count();
        $datatable=array();
        $iseditstr='';
        $isdelstr='';
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@getRbanneredit')) {
            $iseditstr='<button class="btn-white btn btn-xs" onclick="location.href=\'/site/rbanneredit/$reeditstr\'">编辑</button>';
        }
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@postRbannerdel')) {
            $isdelstr='<button class="btn-white btn btn-xs" onclick="singledel(\'/site/rbannerdel\',$redelstr);">删除</button>';
        }
        foreach ($data as $item) {
            $status_at=$item->status_at==1?'<span class="label label-primary">启用</span>':'<span class="label label-danger">禁用</span>';
            $obj=array('<input type="checkbox" name="chk" value='.$item->id.' />',$item->id,$item->title,'<img width="80px" height="60px" src='.$item->image.' />',$item->url,$status_at,str_replace('$reeditstr',$item->id,$iseditstr).str_replace('$redelstr',$item->id,$isdelstr));
            array_push($datatable,$obj);
        }
        $dt['draw']=intval(Input::get('draw',0));
        $dt['data']=$datatable;
        $dt['recordsTotal']=$recordsTotal;
        $dt['recordsFiltered']=$recordsFiltered;
        // $dt['error']='暂时没有数据';
        echo json_encode($dt);     
    }


    public function getRbanneradd(){
        return view('site.rbanneradd');
    }

    public function postRbanneradd(){
        $info = new Rbanner;
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'添加成功！','redirecturl'=>'/site/rbannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'添加失败！','redirecturl'=>'/site/rbannerindex']);
        }
    }
    
    public function getRbanneredit($id){
        $info = Rbanner::find($id);
        return view('site.rbanneredit')->with('info',$info);
    }

    public function postRbanneredit(){
        $info = Rbanner::find(Input::get('id'));
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/rbannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/rbannerindex']);
        }
    }

    public function postRbannerdel(){
        $res=Rbanner::destroy(Input::get('data'));
        if($res){
            die('1');
        }
        else{
            die('0');
        }
    }

    public function postUploadrbanner(){
        if (Input::hasFile('file'))
        {
            $file=Input::file('file');
            if($file -> isValid()){
                $folder='uploads/file/'.date('Ymd');
                if(!file_exists($folder)){
                 mkdir($folder);
                }
                $clientName = $file -> getClientOriginalName();
                // $tmpName = $file->getFileName(); // 缓存在tmp文件夹中的文件名 例如 php8933.tmp 这种类型的.
                // $realPath = $file->getRealPath();    //这个表示的是缓存在tmp文件夹下的文件的绝对路径
                $extension = $file -> getClientOriginalExtension(); //上传文件的后缀.
                // $mimeTye = $file -> getMimeType();//开启php的extension=php_fileinfo.dll
                // $newName = time().$clientName;
                $newName = time().rand(1000, 9999).'.'.$extension;
                $file -> move($folder,$newName);
                // \Image::make($file)->resize(300, 200)->save($folder.'/'.$newName);
                $path='/'.$folder.'/'.$newName;
                // $file->move('uploads');
                $data['file']=array();
                $subdata['name']=$clientName;
                // $subdata['size']=$mimeTye;
                $subdata['url']=$path;
                $data['file'][]=$subdata;
                die(json_encode($data));
            }
        }
    }

    public function getMbannerindex(){
        return view('site.mbannerindex');
    }
    
    //返回DataTable
    public function getMbannerdatatable(){
        $dt=array();
        $orderby = isset( $_GET[ 'order'  ] ) ? $_GET[ 'columns' ][ $_GET[ 'order' ][ 0 ][ 'column' ] ][ 'name' ] : 'id';
        $orderdir = isset( $_GET[ 'order'  ] ) ? $_GET[ 'order' ][ 0 ][ 'dir' ] : 'asc';
        $start = Input::get('start',0);//从多少开始
        $length = Input::get('length',10);//数据长度
        $search = $_GET['search']['value'];//搜索获取前台传过来的过滤条件
        $recordsTotal = Mbanner::count();
        $where='1=1 ';
        if($search!=''){
            $where.='and title like "%'.$search.'%"';
        }
        $data = Mbanner::whereRaw($where)->select('id', 'title','image','url','status_at')->skip($start)->take($length)->orderBy($orderby,$orderdir)->get();
        $recordsFiltered=  Mbanner::whereRaw($where)->count();
        $datatable=array();
        $iseditstr='';
        $isdelstr='';
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@getMbanneredit')) {
            $iseditstr='<button class="btn-white btn btn-xs" onclick="location.href=\'/site/mbanneredit/$reeditstr\'">编辑</button>';
        }
        if (\Gate::check('chkaccess', 'App\Http\Controllers\SiteController@postMbannerdel')) {
            $isdelstr='<button class="btn-white btn btn-xs" onclick="singledel(\'/site/mbannerdel\',$redelstr);">删除</button>';
        }
        foreach ($data as $item) {
            $status_at=$item->status_at==1?'<span class="label label-primary">启用</span>':'<span class="label label-danger">禁用</span>';
            $obj=array('<input type="checkbox" name="chk" value='.$item->id.' />',$item->id,$item->title,'<img width="80px" height="60px" src='.$item->image.' />',$item->url,$status_at,str_replace('$reeditstr',$item->id,$iseditstr).str_replace('$redelstr',$item->id,$isdelstr));
            array_push($datatable,$obj);
        }
        $dt['draw']=intval(Input::get('draw',0));
        $dt['data']=$datatable;
        $dt['recordsTotal']=$recordsTotal;
        $dt['recordsFiltered']=$recordsFiltered;
        // $dt['error']='暂时没有数据';
        echo json_encode($dt);     
    }


    public function getMbanneradd(){
        return view('site.mbanneradd');
    }

    public function postMbanneradd(){
        $info = new Mbanner;
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'添加成功！','redirecturl'=>'/site/mbannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'添加失败！','redirecturl'=>'/site/mbannerindex']);
        }
    }
    
    public function getMbanneredit($id){
        $info = Mbanner::find($id);
        return view('site.mbanneredit')->with('info',$info);
    }

    public function postMbanneredit(){
        $info = Mbanner::find(Input::get('id'));
        $info->title = Input::get('title');
        $info->image = Input::get('image');
        $info->url = Input::get('url');
        $info->status_at = Input::get('status_at',0);
        $res=$info->save();
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/mbannerindex']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/mbannerindex']);
        }
    }

    public function postMbannerdel(){
        $res=Mbanner::destroy(Input::get('data'));
        if($res){
            die('1');
        }
        else{
            die('0');
        }
    }

    public function postUploadmbanner(){
        if (Input::hasFile('file'))
        {
            $file=Input::file('file');
            if($file -> isValid()){
                $folder='uploads/file/'.date('Ymd');
                if(!file_exists($folder)){
                 mkdir($folder);
                }
                $clientName = $file -> getClientOriginalName();
                // $tmpName = $file->getFileName(); // 缓存在tmp文件夹中的文件名 例如 php8933.tmp 这种类型的.
                // $realPath = $file->getRealPath();    //这个表示的是缓存在tmp文件夹下的文件的绝对路径
                $extension = $file -> getClientOriginalExtension(); //上传文件的后缀.
                // $mimeTye = $file -> getMimeType();//开启php的extension=php_fileinfo.dll
                // $newName = time().$clientName;
                $newName = time().rand(1000, 9999).'.'.$extension;
                $file -> move($folder,$newName);
                // \Image::make($file)->resize(300, 200)->save($folder.'/'.$newName);
                $path='/'.$folder.'/'.$newName;
                // $file->move('uploads');
                $data['file']=array();
                $subdata['name']=$clientName;
                // $subdata['size']=$mimeTye;
                $subdata['url']=$path;
                $data['file'][]=$subdata;
                die(json_encode($data));
            }
        }
    }

    public function getDownconfedit(){
        $info = json_decode(file_get_contents(config('site.downconf')));
        return view('site.downconfedit')->with('info',$info);
    }

    public function postDownconfedit(){
        $info = collect(['ftpsrv'=>Input::get('ftpsrv'),'username'=>Input::get('username'),'pwd'=>Input::get('pwd')]);
        $infostr=$info->toJson();
        $res=file_put_contents(config('site.downconf'),$infostr);
        if($res){
            return redirect('tooltip/success')->with(['redirectway'=>'修改成功！','redirecturl'=>'/site/downconfedit']);
        }else{
            return redirect('tooltip/failure')->with(['redirectway'=>'修改失败！','redirecturl'=>'/site/downconfedit']);
        }
    }
}
